package day01.set;

import java.util.HashSet;

/**
 * @author feng
 * @Date 2021/10/17 14:19
 *  set集合 : 唯一、无序
 *   底层:数组+链表
 *  hashset
 *   必须重写hashcode()和equals
 */
public class HashSetTest {
    public static void main(String[] args) {
        HashSet hset = new HashSet();
        hset.add(20);
        hset.add(30);
        hset.add(50);
        hset.add(80);
        hset.add(20);
        System.out.println(hset);
        System.out.println(hset.size());

        System.out.println("--------------");
        HashSet<Student> hashSet = new HashSet();
        // 自定义数据类型
        // 往哈希表中存值，首先计算其hashCode，哈希碰撞时，进行equals比较
        hashSet.add(new Student("李四",20));
        hashSet.add(new Student("王五",30));
        hashSet.add(new Student("李四",20));
        System.out.println(hashSet);
        System.out.println(hashSet.size());

    }
}
